package com.example.luke.shengdangxiaoattendance.Util;

import java.util.ArrayList;

/**
 * Created by luke on 1/1/17.
 */

public class ZYScannerModel {

    Integer READ_SECTOR;

    ArrayList<MIReaderUtils.MIReaderObj> miReaderObjArrayList;

    public void setREAD_SECTOR(Integer READ_SECTOR) {
        this.READ_SECTOR = READ_SECTOR;
    }

    public void setMiReaderObjArrayList(ArrayList<MIReaderUtils.MIReaderObj> miReaderObjArrayList) {
        this.miReaderObjArrayList = miReaderObjArrayList;
    }

    public ArrayList<MIReaderUtils.MIReaderObj> getMiReaderObjArrayList() {
        return miReaderObjArrayList;
    }


    String getMiCardValue(Integer sector, Integer block) {



        MIReaderUtils.MIReaderObj miReaderObj= getCorrespondSectorObj(sector);


        if (miReaderObj.getBlock().size()<3){
            return "00000000000000000000000000000000";

        }else {

//            String value = miReaderObj.getBlock().get(block);

            return miReaderObj.getBlock().get(block);
        }


    }

    MIReaderUtils.MIReaderObj getCorrespondSectorObj(int sector){
        MIReaderUtils.MIReaderObj miReaderObj=new MIReaderUtils.MIReaderObj();
        for (MIReaderUtils.MIReaderObj temp:this.miReaderObjArrayList){
            GlobalFunction.printTextByTag(temp.getSector()+""+" sector");

            if (temp.getSector().equals(sector)){
                miReaderObj=temp;

                break;

            }
        }
        return miReaderObj;

    }

    Integer getBackUpIndex(){
        Integer index=0;
        String value=getMiCardValue(READ_SECTOR,0).substring(0,4);
        String value2=getMiCardValue(READ_SECTOR,1).substring(0,4);

        Integer integer= Integer.valueOf(MIReaderUtils.convertToDecimal(value));
        Integer integer2= Integer.valueOf(MIReaderUtils.convertToDecimal(value2));
        if (integer>integer2){
            index=0;

        }else if(integer2>integer){
            index=1;

        }else {
            value= getMiCardValue(READ_SECTOR, 1).substring(8, 14);

            String temp=MIReaderUtils.convertToDecimal(value);
            Integer integer3= Integer.valueOf(temp);

            String value3=MIReaderUtils.convertToDecimal(getMiCardValue(READ_SECTOR, 0).substring(8, 14)) ;
            Integer integer1= Integer.valueOf(value3);

            if (integer1<integer3){
                index=0;

            }else {
                index=1;
            }
        }

        return index;

    }


}
